import java.util.HashSet;
import java.util.Set;

public class Leetcode653 {

    public boolean findTarget(TreeNode root, int k) {
        return find(root, new HashSet<>(), k);
    }

    private boolean find(TreeNode node, Set<Integer> set, int target) {
        if (node == null) {
            return false;
        }

        if (set.contains(target - node.val)) {
            return true;
        }

        set.add(node.val);

        return find(node.left, set, target) || find(node.right, set, target);
    }
}
